<?php
session_start();
include_once("./configuration.php");
/* This is what happens from "preview" -button. At first we generate temporary filter list */
if($_SESSION['logged']) {
	$ignore_file = $_SESSION['homedir'].$_POST['filename'].".filter.txt";
	$anonymize_file = $_SESSION['homedir'].$_POST['filename'].".anonymize.txt";
	$ignore = fopen($ignore_file, "a");
	$level = escapeshellarg(trim($_POST['level']));
	$ano = fopen($anonymize_file, "a");
	foreach($_POST as $key=>$value) {
		if($value == "ignore") {
			fwrite($ignore, $key."\n");
			fwrite($ignore, strtolower($key)."\n");
		}
		if($value == "delete") {
			fwrite($ano, $key."\n");
		}
		if(preg_match("/new_entry/", $key)) {
		  if(strlen($value) > 1) fwrite($ano, $value."\n");
		}
	}
	$inputfile = $_SESSION['uploads'].$_POST['filename'];
	$base = explode(".",$_POST['filename']); 
	unset($base[sizeof($base)-1]); 
$base=implode(".", $base);
	$outputfile = $_SESSION['completed'].$base.".html";
	$outputfile_pdf = $_SESSION['completed'].$base.".pdf";

	$javadir = dirname(__FILE__)."/logic/";
	$cmd_pdf = "cd $javadir && export JAVA_HOME=".$javapath." ; java -jar logic.jar -clean pdf -input ".escapeshellarg($inputfile)." -level ".$level." -ignore ".escapeshellarg($ignore_file)." -anonymize ".escapeshellarg($anonymize_file)." -output ".escapeshellarg($outputfile_pdf);
	shell_exec($cmd_pdf); 
}
header("Location: ./index.php?p=file_management");
?>
